﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import reprise.tweens.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.utils.*;
    import com.robertpenner.easing.*;

    public class CreateRewardAnimationFromHospitalCommand extends Command {

        public var event:InfoEvent;
        public var popupModel:PopupModel;
        private var _iconToAnimate:MovieClip;

        override public function execute():void{
            var _local5:Point;
            var _local8:Number;
            var _local9:Number;
            var _local1 = 45;
            var _local2:Object = this.event.info;
            var _local3:MovieClip = _local2[EventConstants.ITEM_TO_COLLECT];
            var _local4:String = _local2[EventConstants.ITEM_TYPE];
            log(_local4);
            _local5 = this.getTargetPosition(_local4);
            var _local6:Rectangle = _local3.getRect(contextView.stage);
            var _local7:Point = _local3.parent.localToGlobal(new Point(_local3.x, _local3.y));
            this._iconToAnimate = AssetsLibrary.getMovieClip(_local4);
            _local8 = (_local6.height / this._iconToAnimate.height);
            this._iconToAnimate.x = _local7.x;
            this._iconToAnimate.y = _local7.y;
            _local9 = (_local1 / this._iconToAnimate.height);
            this._iconToAnimate.scaleX = (this._iconToAnimate.scaleY = _local8);
            this._iconToAnimate.visible = !(this.popupModel.isPopupOpen());
            contextView.stage.addChild(this._iconToAnimate);
            this._iconToAnimate.cacheAsBitmap = true;
            var _local10:SimpleTween = new SimpleTween(350);
            _local10.addTweenProperty(this._iconToAnimate, "x", this._iconToAnimate.x, _local5.x, Quad.easeOut);
            _local10.addTweenProperty(this._iconToAnimate, "y", this._iconToAnimate.y, _local5.y, Quad.easeOut);
            _local10.addTweenProperty(this._iconToAnimate, "scaleX", this._iconToAnimate.scaleX, _local9, Quad.easeOut);
            _local10.addTweenProperty(this._iconToAnimate, "scaleY", this._iconToAnimate.scaleY, _local9, Quad.easeOut);
            _local10.addEventListener(Event.COMPLETE, this.rewardAnimation_complete);
            _local10.execute();
        }
        private function rewardAnimation_complete(_arg1:Event):void{
            contextView.stage.removeChild(this._iconToAnimate);
            this._iconToAnimate = null;
        }
        private function getTargetPosition(_arg1:String):Point{
            var _local2:Point;
            var _local3 = !((_arg1.indexOf("Collection") == -1));
            if (_local3){
                _local2 = GameConstants.REWARD_MENU_POSITION_COLLECTION;
                return (_local2);
            };
            switch (_arg1){
                case GameConstants.REWARD_COFFEE:
                case GameConstants.REWARD_COFFEE_PACK:
                    _local2 = GameConstants.REWARD_MENU_POSITION_COFFEE;
                    break;
                case GameConstants.REWARD_BATTERY:
                    _local2 = GameConstants.REWARD_MENU_POSITION_BATTERY;
                    break;
                case GameConstants.REWARD_LOVE:
                    _local2 = GameConstants.REWARD_MENU_POSITION_LOVE;
                    break;
                case GameConstants.REWARD_ICE:
                    _local2 = GameConstants.REWARD_MENU_POSITION_ICE;
                    break;
                case GameConstants.REWARD_FIRE:
                    _local2 = GameConstants.REWARD_MENU_POSITION_FIRE;
                    break;
                case GameConstants.REWARD_AIR:
                    _local2 = GameConstants.REWARD_MENU_POSITION_AIR;
                    break;
                case GameConstants.REWARD_STAR:
                    _local2 = GameConstants.REWARD_MENU_POSITION_STAR;
                    break;
                case GameConstants.REWARD_WATER:
                    _local2 = GameConstants.REWARD_MENU_POSITION_WATER;
                    break;
                case GameConstants.REWARD_COIN_STACK:
                    _local2 = GameConstants.REWARD_MENU_POSITION_COINS;
                    break;
                case GameConstants.REWARD_COIN:
                    _local2 = GameConstants.REWARD_MENU_POSITION_COINS;
                    break;
                case GameConstants.REWARD_GOLD:
                    _local2 = GameConstants.REWARD_MENU_POSITION_COINS;
                    break;
                case GameConstants.REWARD_BOOST:
                    _local2 = GameConstants.REWARD_MENU_POSITION_BOOSTS;
                    break;
                case GameConstants.REWARD_XP:
                case GameConstants.REWARD_XP_PACK:
                    _local2 = GameConstants.REWARD_MENU_POSITION_XP;
                    break;
                case GameConstants.REWARD_GOODS:
                    _local2 = GameConstants.REWARD_MENU_POSITION_GOODS;
                    break;
                case GameConstants.REWARD_COLOR_CONE:
                case GameConstants.REWARD_MILK_BOTTLE:
                case GameConstants.REWARD_PACIFIER:
                case GameConstants.REWARD_ROLLING_TOY:
                case GameConstants.REWARD_WOODEN_GIRAFFE:
                case GameConstants.REWARD_RICE_PUDDING:
                    _local2 = GameConstants.REWARD_MENU_POSITION_INVENTORY_TAB;
                    dispatch(new InfoEvent(EventConstants.SELECT_MENU_TAB, GameConstants.MENU_TAB_INVENTORY));
                    break;
                default:
                    log("e no target position");
                    break;
            };
            return (_local2);
        }

    }
}//package net.wooga.pets.controllers 
